package findMaxAverage;

public class Solution {
    public double findMaxAverage(int[] nums, int k) {
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum+=nums[i];
        }
        int res = sum;
        for (int i = 1; i <nums.length-k ; i++) {
            sum-=nums[i-1];
            sum+=nums[i+k];
            res = Math.max(sum,res);
        }
        return (1.0*res)/k;
    }
}
